package com.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.mapper.NewsMapper;
import com.pojo.News;
import com.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsService service;


    @GetMapping("/pages_{page}")
    public List<News> findByPage(@PathVariable(name = "page", required = true) int page, @RequestParam(name = "size", required = true, defaultValue = "10") int size) {
        List<News> newsList = service.findByPage(page, size);
        return newsList;
    }

    @GetMapping("/lu_{page}")
    public PageInfo<List<News>> find(@PathVariable(name = "page", required = true) int page, @RequestParam(name = "size", required = true, defaultValue = "10") int size) {
        List<News> newsList = service.findByPage(page, size);
        PageInfo<List<News>> info = new PageInfo(newsList);
        System.out.println(info);
        return info;
    }


}
